package com.frankle.jfx.antd;

import com.frankle.jfx.antd.components.common.AntButton;
import com.frankle.jfx.antd.components.dataview.AntList;
import com.frankle.jfx.antd.doc.ButtonDocPane;
import com.frankle.jfx.antd.enums.button.AButtonSize;
import com.frankle.jfx.antd.enums.button.AntButtonType;
import com.sun.javafx.fxml.builder.URLBuilder;
import com.sun.javafx.tk.Toolkit;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.geometry.Rectangle2D;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.stage.Screen;
import javafx.stage.Stage;

import java.net.URL;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;

public class Main extends Application {

    public static final ConcurrentHashMap<String, Stage> STAGE_MAP = new ConcurrentHashMap<>();

    private static double WIDTH = 800;
    private static double HEIGHT = 600;

    @Override
    public void start(Stage stage) throws Exception {
		//获取屏幕宽度
		Screen primaryScreen = Screen.getPrimary();
		Rectangle2D bounds = primaryScreen.getBounds();

		WIDTH = bounds.getWidth();
		HEIGHT = bounds.getHeight();

		SplitPane splitPane = new SplitPane();
		splitPane.setOrientation(Orientation.HORIZONTAL);
		splitPane.setBackground(Background.EMPTY);
		splitPane.setPrefWidth(800);
		splitPane.setPrefHeight(600);
		splitPane.setDividerPosition(0, 0.1);

		AntList<String> listView = new AntList<>();
		listView.setPrefWidth(100);
        listView.setPrefHeight(-1);

		listView.setItems(FXCollections.observableList(List.of("按钮")));
        listView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
        listView.getSelectionModel()
                .selectedItemProperty()
                .addListener(((observableValue, oldValue, newValue) -> {
                    System.out.println(newValue);
                }));

		VBox vBox = new VBox();
		vBox.setSpacing(20);

		HBox hBox = new HBox();
		hBox.setSpacing(20);
		hBox.setPadding(new Insets(20));
        hBox.setFillHeight(true);

		AntButton button = new AntButton("按钮");

		AntButton primaryButton = new AntButton("主要按钮");
		primaryButton.setType(AntButtonType.PRIMARY);

		AntButton dangerButton = new AntButton("危险按钮");
		dangerButton.setType(AntButtonType.DANGER);

		AntButton linkButton = new AntButton("链接按钮");
		linkButton.setType(AntButtonType.LINK);

		AntButton textButton = new AntButton("文本按钮");
		textButton.setType(AntButtonType.TEXT);

        HBox btnBox = new HBox();
        btnBox.setSpacing(20);
        btnBox.setPadding(new Insets(20));

		ObservableList<Node> btnBoxChildren = btnBox.getChildren();
		btnBoxChildren.addAll(button, primaryButton, dangerButton, linkButton, textButton);

		//尺寸
		HBox sizeBox = new HBox();
		sizeBox.setSpacing(20);
		sizeBox.setPadding(new Insets(20));

		AntButton smallButton = new AntButton("小按钮");
		smallButton.setSize(AButtonSize.SMALL);

		AntButton middleButton = new AntButton("中按钮");
		middleButton.setSize(AButtonSize.MIDDLE);

		AntButton largeButton = new AntButton("大按钮");
		largeButton.setSize(AButtonSize.LARGE);

		ObservableList<Node> sizeBoxChildren = sizeBox.getChildren();
		sizeBoxChildren.addAll(smallButton, middleButton, largeButton);

		ButtonDocPane buttonDocPane = FXMLLoader.load(getClass().getResource("/views/doc/ButtonDocView.fxml").toURI().toURL());

		ScrollPane sp = new ScrollPane(buttonDocPane);
		sp.setBackground(Background.EMPTY);
		System.out.println(sp);

		StackPane stackPane = new StackPane();
        stackPane.setBorder(Border.stroke(Color.BLACK));
        stackPane.setAlignment(Pos.TOP_LEFT);
        stackPane.setPrefSize(-1, -1);
		stackPane.setBackground(Background.EMPTY);
        stackPane.getChildren().add(sp);

		splitPane.getItems().addAll(listView, stackPane);

		Scene root = new Scene(splitPane, splitPane.getPrefWidth(), splitPane.getPrefHeight());
        ObservableList<String> stylesheets = root.getStylesheets();
        stylesheets.add(getClass().getResource("/css/app.css").toExternalForm());
        stylesheets.add(getClass().getResource("/css/theme/ant-design-jfx.css").toExternalForm());

		stage.setScene(root);
		stage.setTitle("Ant Design JavaFX");
		stage.setResizable(true);
		stage.setWidth(WIDTH);
		stage.setHeight(HEIGHT);
		stage.getIcons().add(new Image(getClass().getResourceAsStream("/images/logo.png")));

		STAGE_MAP.put("main", stage);
		stage.setMaximized(true);
		stage.show();
    }
}
